package com.elong.businesstravel.modules.init;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.elong.businesstravel.R;
import com.elong.businesstravel.base.baseactivity.BaseActivity;
import com.elong.businesstravel.modules.home.HomeActivity;
import com.elong.businesstravel.modules.init.adapter.GuideAdapter;

/**
 * 引导页
 * 
 * @author lenovo
 * 
 */
public class GuideActivity extends BaseActivity {

	private ViewPager mViewPager;
	private GuideAdapter mGuideAdapter;

	private int[] mImageIds = { R.drawable.guide_pic1, R.drawable.guide_pic2,
			R.drawable.guide_pic3 };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
		// WindowManager.LayoutParams.FLAG_FULLSCREEN);
		// this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_guide);

		mViewPager = (ViewPager) findViewById(R.id.viewPager);
		mGuideAdapter = new GuideAdapter(mContext, mImageIds, mViewPager);
		mViewPager.setAdapter(mGuideAdapter);
		mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int arg0) {
				if (mImageIds.length - 1 == arg0) {
					View view = mViewPager.getChildAt(arg0);
					if (null != view) {
						ImageView imageView = (ImageView) view
								.findViewById(R.id.imageView);
						imageView.setOnClickListener(new OnClickListener() {

							@Override
							public void onClick(View v) {
								Intent intent = new Intent(mContext,
										HomeActivity.class);
								startActivity(intent);
								finish();
								overridePendingTransition(
										android.R.anim.fade_in,
										android.R.anim.fade_out);
							}
						});
					}
				}
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {

			}

			@Override
			public void onPageScrollStateChanged(int arg0) {

			}
		});
	}

}
